package main

import "fmt"

//#link: https://leetcode-cn.com/problems/total-hamming-distance/
func main() {
	nums := []int{1337, 7331}
	fmt.Println(totalHammingDistance(nums))
}

//统计第i位的1的个数，若1的个数为 c,则0的个数为 len(nums)-c,第i位上的总数为c*(len(nums)-c)
func totalHammingDistance(nums []int) int {
	result := 0
	for i := 0; i < 30; i++ {
		temp := 0
		for _, value := range nums {
			temp += (value >> uint(i)) & 1
		}
		result += temp * (len(nums) - temp)
	}
	return result
}
